#include <netinet/in.h>    // for sockaddr_in
#include <sys/types.h>    // for socket
#include <sys/socket.h>    // for socket
#include <stdio.h>        // for printf
#include <stdlib.h>        // for exit
#include <string.h>        // for bzero
#include <netinet/in.h>
#include<arpa/inet.h>

#include<unistd.h>
int main(){
    printf("1");

    struct sockaddr_in server_addr;
    server_addr.sin_family=AF_INET;
//    server_addr.sin_addr.s_addr=htons(INADDR_ANY);
    server_addr.sin_addr.s_addr=inet_addr("127.0.0.1");
//    server_addr.sin_addr.s_addr=inet_addr("192.168.0.129");


    server_addr.sin_port=htons(9000);

    //创建server socket
    int server_fd=socket(PF_INET,SOCK_STREAM,0);

    if(server_fd<0){
        printf("create server socket failed");
        exit(1);
    }
    int opts=1;
    setsockopt(server_fd,SOL_SOCKET,SO_REUSEADDR,&opts, sizeof(opts));

    int bind_result=bind(server_fd,(struct sockaddr*)&server_addr, sizeof(server_addr));
    if(bind_result){
        printf("Server Bind Port :Failed!");
        exit(1);
    }
    if(listen(server_fd,20)){
        printf("Server Listen Failed!");
        exit(1);
    }
    int	i;
    for(i = 0; i < 6; i++){//连续创建六个子进程
        int pid = fork();
        printf("%d",pid);
        if(pid == 0) break;
    }

    struct  sockaddr_in client_addr;
    socklen_t length= sizeof(client_addr);
    printf("1");
    accept(server_fd,(struct socketaddr*)&client_addr,&length);
    printf("2");

    return 0;
}